<?php
session_start();
define('app_path',dirname(dirname(__FILE__)).'/');
define('environment','idc');
define('phpKey','8abf7b4dc529a5b9ef624731ee71e9c7');
require_once app_path.'vendor/autoload.php';
$config=require_once app_path.'config/base.php';
ini_set('date.timezone','Asia/Shanghai');
include_once 'helper/function.php';
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$register = new \lib\register();
//把类搞成全局
$view = new \lib\view('template',app_path);
$register->set('view',$view);

$db = new \lib\db();
$register->set('db',$db);

if(!$_SESSION['admin'] && $_GET['act']!='login' && $_GET['act'] !="logout" && !isset($_GET['pid']) && !isset($_GET['apiToken']))
{
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || $_GET['json']==1) {
            echo  json_encode(['session'=>0]);
        }
        else{
            require_once 'build/login.html';
        }
       exit;
}
elseif($_SESSION['admin']['key'] && $_SESSION['admin']['key'] !=phpKey){
    die("hacking attempt");
}